package com.example.spring2303;

import com.example.spring2303.bean.Customer;
import com.example.spring2303.bean.CustomerByAno;
import com.example.spring2303.bean.MyConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
@RequestMapping("/test")
public class Spring2303Application {

    public static void main(String[] args) {
        SpringApplication.run(Spring2303Application.class, args);

//        基于xml方式装载bean
//        ApplicationContext con = new ClassPathXmlApplicationContext("myApp.xml");
//        Customer customer = (Customer) con.getBean("cu2");
//        System.out.println("id=" + customer.getId() + "username=" +
//                customer.getUsername() + "密码=" + customer.getPassword());

//        基于注解方式转载bean并注入
        ApplicationContext con = new AnnotationConfigApplicationContext(MyConfig.class);
        CustomerByAno ano = con.getBean(CustomerByAno.class);
        System.out.println("id=" +ano.getId() + ";username=" + ano.getUsername() + ";pwd=" + ano.getPassword());

    }

    @GetMapping("/hello")
    public String hello() {
        return "my first spring project";
    }

}
